import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JScrollBar;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import java.io.IOException;
import java.util.logging.*;
import javax.swing.SwingConstants;

/**
 * A Doctor's screen once they log in.
 * @author Team 1: Thunder/Dragon
 *
 */

public class DoctorPanel extends JPanel {
        private static Logger doctorPanelLog = 
        	Logger.getLogger(DoctorPanel.class.getName());
        private JButton btnViewSchedule;
        private JButton btnViewRecord;
        private JButton btnAddPatient;
        private JButton btnDeletePatient;
        private JButton btnFindPatient;
        private JButton btnCreateRec;
        private JButton btnEditPatient;

        static{
                ConsoleHandler console = new ConsoleHandler();
                console.setLevel(Level.ALL);
                console.setFormatter(new ThunderDragonHtmlFormatter());
                doctorPanelLog.addHandler(console);
                doctorPanelLog.setLevel(Level.ALL);
               
                try {
                        FileHandler fh = new FileHandler("DoctorPanelLog.txt");
                        fh.setFormatter(new ThunderDragonHtmlFormatter());
                        doctorPanelLog.addHandler(fh);
                } catch (SecurityException e) {
                        // TODO Auto-generated catch block
                        doctorPanelLog.severe("Failure: Security exception thrown " +
                        		"when trying to create a new handler " +
                        		"in DoctorPanelLog.java.");
                        e.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        doctorPanelLog.severe("Failure: I/O exception thrown" +
                        		" when trying to create a new handler " +
                        		"in DoctorPanelLog.java.");
                        e.printStackTrace();
                }
               
        }
        

    	private class ButtonListen implements ActionListener{

    		public void actionPerformed(ActionEvent e) {
    			if(e.getSource().equals(btnAddPatient)){
    				btnAddPatient.getParent().firePropertyChange("addPatient", 0, 1);
    			}
    			else if(e.getSource().equals(btnDeletePatient)){
    				btnDeletePatient.getParent().firePropertyChange("deletePatient", 0, 1);
    			}
    			else if(e.getSource().equals(btnEditPatient)){
    				btnEditPatient.getParent().firePropertyChange("editPatient", 0, 1);
    			}
    			else if(e.getSource().equals(btnFindPatient)){
    				btnFindPatient.getParent().firePropertyChange("findPatient", 0, 1);
    			}
    			else if(e.getSource().equals(btnCreateRec)){
    				btnCreateRec.getParent().firePropertyChange("createRec", 0, 1);
    			}
    			else if(e.getSource().equals(btnViewRecord)){
    				btnViewRecord.getParent().firePropertyChange("viewRec", 0, 1);
    			}
    			else if(e.getSource().equals(btnViewSchedule)){
    				btnViewSchedule.getParent().firePropertyChange("viewSchedule", 0, 1);
    			}
    			
    		}
    		
    		public String toString(){
    			return "A string for the button.";
    		}
    		
    	}


        /**
         * The panel of the Doctor.
         */
        public DoctorPanel() {
                doctorPanelLog.entering(this.getClass().getName(), 
                		"DoctorPanel Constructor");
               
                SpringLayout springLayout = new SpringLayout();
                setLayout(springLayout);
                
                btnAddPatient = new JButton("Add Patient");
                springLayout.putConstraint(SpringLayout.WEST, 
                		btnAddPatient, 10, SpringLayout.WEST, this);
                springLayout.putConstraint(SpringLayout.EAST, 
                		btnAddPatient, 140, SpringLayout.WEST, this);
                springLayout.putConstraint(SpringLayout.NORTH,
                		btnAddPatient, 65, SpringLayout.NORTH, this);
                add(btnAddPatient);
                btnAddPatient.addActionListener(new ButtonListen());
                
                btnDeletePatient = new JButton("Delete Patient");
                springLayout.putConstraint(SpringLayout.NORTH, 
                		btnDeletePatient, 6, SpringLayout.SOUTH, btnAddPatient);
                springLayout.putConstraint(SpringLayout.WEST, 
                		btnDeletePatient, 10, SpringLayout.WEST, this);
                springLayout.putConstraint(SpringLayout.EAST, 
                		btnDeletePatient, 140, SpringLayout.WEST, this);
                add(btnDeletePatient);
                btnDeletePatient.addActionListener(new ButtonListen());
                
                btnFindPatient = new JButton("Find Patient");
                springLayout.putConstraint(SpringLayout.WEST, btnFindPatient, 0, SpringLayout.WEST, btnAddPatient);
                springLayout.putConstraint(SpringLayout.EAST, 
                		btnFindPatient, 140, SpringLayout.WEST, this);
                add(btnFindPatient);
                btnFindPatient.addActionListener(new ButtonListen());
                
                btnCreateRec = new JButton("Create Record");
                springLayout.putConstraint(SpringLayout.NORTH, btnCreateRec, 181, SpringLayout.NORTH, this);
                springLayout.putConstraint(SpringLayout.WEST, btnCreateRec, 0, SpringLayout.WEST, btnAddPatient);
                springLayout.putConstraint(SpringLayout.EAST, btnCreateRec, 0, SpringLayout.EAST, btnAddPatient);
                add(btnCreateRec);
                btnCreateRec.addActionListener(new ButtonListen());
                
                 btnViewRecord = new JButton("View Record");
                 springLayout.putConstraint(SpringLayout.NORTH, btnViewRecord, 6, SpringLayout.SOUTH, btnCreateRec);
                 springLayout.putConstraint(SpringLayout.WEST, btnViewRecord, 0, SpringLayout.WEST, btnAddPatient);
                 springLayout.putConstraint(SpringLayout.EAST, 
                 		btnViewRecord, 140, SpringLayout.WEST, this);
                 add(btnViewRecord);
                 btnViewRecord.addActionListener(new ButtonListen());
                
                 btnViewSchedule = new JButton("View Schedule");
                 springLayout.putConstraint(SpringLayout.NORTH, btnViewSchedule, 6, SpringLayout.SOUTH, btnViewRecord);
                 springLayout.putConstraint(SpringLayout.WEST, btnViewSchedule, 0, SpringLayout.WEST, btnAddPatient);
                 springLayout.putConstraint(SpringLayout.EAST, btnViewSchedule, 0, SpringLayout.EAST, btnAddPatient);
                 add(btnViewSchedule);
                 btnViewSchedule.addActionListener(new ButtonListen());
                
                JLabel lblDoctor = new JLabel("Doctor");
                springLayout.putConstraint(SpringLayout.WEST, 
                		lblDoctor, 10, SpringLayout.WEST, this);
                springLayout.putConstraint(SpringLayout.EAST, 
                		lblDoctor, -10, SpringLayout.EAST, this);
                lblDoctor.setFont(new Font("Pristina", Font.ITALIC, 18));
                lblDoctor.setHorizontalAlignment(SwingConstants.CENTER);
                springLayout.putConstraint(SpringLayout.NORTH, 
                		lblDoctor, 10, SpringLayout.NORTH, this);
                add(lblDoctor);
                
                JLabel label = new JLabel("Menu");
                springLayout.putConstraint(SpringLayout.NORTH, 
                		label, 5, SpringLayout.SOUTH, lblDoctor);
                springLayout.putConstraint(SpringLayout.WEST, 
                		label, 10, SpringLayout.WEST, this);
                springLayout.putConstraint(SpringLayout.EAST, 
                		label, 140, SpringLayout.WEST, this);
                label.setHorizontalAlignment(SwingConstants.CENTER);
                label.setFont(new Font("Pristina", Font.ITALIC, 18));
                add(label);
                
                btnEditPatient = new JButton("Edit Patient");
                springLayout.putConstraint(SpringLayout.NORTH, btnFindPatient, 6, SpringLayout.SOUTH, btnEditPatient);
                springLayout.putConstraint(SpringLayout.SOUTH, btnFindPatient, 29, SpringLayout.SOUTH, btnEditPatient);
                springLayout.putConstraint(SpringLayout.NORTH, btnEditPatient, 6, SpringLayout.SOUTH, btnDeletePatient);
                springLayout.putConstraint(SpringLayout.SOUTH, btnEditPatient, 29, SpringLayout.SOUTH, btnDeletePatient);
                springLayout.putConstraint(SpringLayout.WEST, btnEditPatient, 0, SpringLayout.WEST, btnAddPatient);
                springLayout.putConstraint(SpringLayout.EAST, btnEditPatient, 0, SpringLayout.EAST, btnAddPatient);
                add(btnEditPatient);
               
                doctorPanelLog.exiting(this.getClass().getName(),
                		"DoctorPanel Constructor");

        }
	public JButton getBtnViewSchedule() {
		return btnViewSchedule;
	}
	public JButton getBtnFindPatientviewRecord() {
		return btnViewRecord;
	}
	public JButton getButton() {
		return btnAddPatient;
	}
	public JButton getButton_1() {
		return btnDeletePatient;
	}
	public JButton getButton_2() {
		return btnFindPatient;
	}
	public JButton getButton_3() {
		return btnCreateRec;
	}
	public JButton getBtnEditPatient() {
		return btnEditPatient;
	}
}


